﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Cms.Domain;
using Cms.Tests.Unit.TestUtils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cms.Tests.Unit.Domain
{

    [TestClass]
    public class MenuItemTests
    {

        [TestMethod]
        public void CloneValueProperties_Success()
        {
            MenuVersion original = MenuTestsHelper.CreateVersion();
            MenuVersion clone = (MenuVersion)original.Clone();
            Assert.AreEqual(3, clone.Items.Count);
            Assert.AreEqual("Parent", clone.GetRootItems()[0].Translations[1].Name);
            Assert.AreEqual(original.Items[0].EndPublishing.Value, clone.Items[0].EndPublishing.Value);
            Assert.AreEqual(MenuItemLinkType.Page, clone.Items[0].LinkType);
            Assert.AreSame(original.Items[0].MediaFile, clone.Items[0].MediaFile);
            Assert.AreSame(original.Items[0].Page, clone.Items[0].Page);
            Assert.AreEqual(original.Items[2].SortIndex, clone.Items[2].SortIndex);
            Assert.AreEqual(original.Items[0].StartPublishing.Value, clone.Items[0].StartPublishing.Value);
            Assert.AreEqual(original.Items[0].Target, clone.Items[0].Target);
        }


        [TestMethod]
        public void CompareTo()
        {
            MenuItem m1 = new MenuItem { SortIndex = 1 };
            MenuItem m2 = new MenuItem { SortIndex = 2 };
            MenuItem m3 = new MenuItem { SortIndex = 1 };
            Assert.AreEqual(1, m1.CompareSortIndexTo(null));
            Assert.AreEqual(-1, m1.CompareSortIndexTo(m2));
            Assert.AreEqual(0, m1.CompareSortIndexTo(m3));
            Assert.AreEqual(1, m2.CompareSortIndexTo(m1));
        }


        [TestMethod]
        public void GetTranslation_Success()
        {
            MenuVersion v = MenuTestsHelper.CreateVersion();
            Assert.AreEqual("Parent", v.Items[0].GetTranslation(1).Name);
        }


        [TestMethod]
        public void GetLevelInTree()
        {
            MenuVersion v = MenuTestsHelper.CreateVersion();
            Assert.AreEqual(0, v.Items[0].GetLevelInTree());
            Assert.AreEqual(1, v.Items[0].SubItems[0].GetLevelInTree());
            Assert.AreEqual(2, v.Items[0].SubItems[0].SubItems[0].GetLevelInTree());
        }


        [TestMethod]
        public void IsParentTo_CheckOnGrandChild_Success()
        {
            MenuVersion v = MenuTestsHelper.CreateVersion();
            Assert.IsTrue(v.Items[0].IsParentTo(v.Items[0].SubItems[0].SubItems[0]));
        }


        [TestMethod]
        public void IsParentTo_CheckOnParentToItself_Failure()
        {
            MenuVersion v = MenuTestsHelper.CreateVersion();
            Assert.IsFalse(v.Items[0].SubItems[0].IsParentTo(v.Items[0]));
        }

    }

}
